/*-----------------------------------------------------------------------------*
																			   
 TITLE: 				Tempering the taste for vengeance - Information about 
						prisoners and policy choices in Chile
 PROJECT: 				Prison and Education 
 CORRESPONDING AUTHOR:	Carlos Scartascini (carlossc@iadb.org)
 CODE AUTHOR:			Fernando G. Cafferata (fernando.cafferata@gmail.com)
 CODE EDITED BY:		Susana Otálvaro-Ramírez (susanaot@iadb.org)
 
 DATE CREATED: 			July 8, 2021						   
 LAST MODIFIED: 		December 13, 2021
 SOFTWARE VERSION:		Stata 17
																			   
 DESCRIPTION: 			Summary stats, regressions, graphs and robust checks
 
				Inputs: 
						- "${data}/Taste_for_Vengeance_Paper.dta"
						- "${data}/Coins_countries.dta"
						
				Outputs: 
						- "${output}/Rev_dec21/"
						
********************************************************************************
									INDEX
********************************************************************************
		0. Preliminary setting
		
		1. Balance table
			a. Table 1 - Balance on observable variables between treatment and control
			
		2. Main results
			a. Table 2 - Impact of Information about Prisoner's Education on Policy Preferences (coin assignment - difference between policy types)
			b. Figure 3 - Coins assigned to punitiveness and social policies among countries
			c. Figure 4 - Average Treatment Effect of Information 
				
		3. Appendix results
			a. Table A1 - Impact of Information about Prisoner's Education on Policy Preferences (coin assignment - raw)
			b. Table A2 - Robustness checks of the Impact of Information about Prisioner's Education on Policy Preferences (SURE, Shares, Ratios)
			c. Figure A2 - Distribution of coins - control group
			d. Figure A3 - Distribution of coins - treatment vs. control
			e. Figure A4 - Average Treatment Effect of Information and Placebo
			f. Figure A5 - Heterogeneous effects: Main problem crime and violence
			g. Figure A6 - Heterogeneous effects: Perception of neighborhood insecurity
			h. Figure A7 - Heterogeneous effects: Education level 
			i. Figure A8 - Heterogeneous effects: Government involvement in income inequality alleviation policies
*-----------------------------------------------------------------------------*/
cls 
drop _all
clear all
clear mata
clear matrix
set more off

graph set window fontface "Century Schoolbook"
set scheme s1color

*---------------------------------------*
* 0. PRELIMINARY SETTING 				*
*---------------------------------------*

** Directories
* Carlos
if "`c(username)'"=="carlossc" {
	di in red "Carlos Scartascini"
	glo path 	= "C:\Users\carlossc\Documents\DATA.IDB\Documents\Personal\RES\Crime\TC PolEcon Crime\LAPOP_ExpSurvey\LAPOP"
	glo data 	= "$path\1. DATA\DTA"
	glo output	= "$path\3. SALIDAS"
	
	cap n mkdir "$output\Rev_dec21"
	glo results = "$output\Rev_dec21"
}

* Fernando
if "`c(username)'"=="" {
	di in red "Fernando Cafferata"
	glo path 	= ""
	glo data	= "$path\"
	glo output	= "$path\" 
	glo results = "$output\Rev_july21"
}

* Susana 
if "`c(username)'"=="SUSANAOT" {
	di in red "Susana Otalvaro"
	glo path 	= "C:\Users\SUSANAOT\OneDrive - Inter-American Development Bank Group\SUSANAOT\99_Other\PB_EducationCrime"
	glo data	= "$path\data"
	glo output	= "$path\output" 
	
	cap n mkdir "$output\Rev_dec21"
	glo results = "$output\Rev_dec21"
}

* For other replicants 
if "`c(username)'"=="" {
	di "You have set your username correctly, folders are going to be set"
	glo path	= "" 			// Folder where you downloaded or saved the code 
	glo data	= "$path\data"	// Indicate the folder where you unzipped the data
	glo results	= "$path\" 		// Create your own results folder.
}

cd "$results"

** Database 
use "$data\Taste_for_Vengeance_Paper.dta", clear
svyset upm [pw=wt], strata(estratopri)	

** Globals
	glo dependent_vars   	"pen_soc pen_det"
	glo dependent_vars2 	"acceptmanodura"
	glo dependent_vars3 	"pen_coin det_coin soc2_coin"
	glo dependent_shares	"sh_pen sh_det sh_soc2"
	glo treatment 			"ITT1 ITT2"
	glo balance 			"sex age ethn_1 ethn_2 ethn_3 ethn_4 ethn_5 ethn_6 education d_employed victim d_neigh_insec d_left d_prob_crimebroad d_informed bribe_police"
	glo vars_str 			"sex i.etid age education d_employed victim d_neigh_insec d_left d_prob_crimebroad d_informed bribe_police i.estratopri"
	glo vars_str1 			"sex age education d_employed victim d_neigh_insec d_left d_prob_crimebroad d_informed bribe_police"

la var ITT1 "Pl: Police corruption info"
la var ITT2 "Tr: Education profile info"



*---------------------------------------*
* 1. BALANCE TABLE 						*
*---------------------------------------*

** a. Table 1 - Balance on observable characteristics
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
	estpost ttest $balance, by (treatment_paper)
	esttab using Table1.tex, replace cells("mu_1(fmt(2)) mu_2(fmt(2)) p(fmt(2))") label

	* There is also balance with individuals assigned to the first treatment group (not reported in table)
	gen 	placebo = (treatment==1)
	replace placebo = . if treatment==2
	estpost ttest $balance, by (placebo)

*---------------------------------------*
* 2. MAIN RESULTS 						*
*---------------------------------------*

** a. Table 2 - OLS Regression 
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
	su pen_soc if treatment==0
	loc c_mean : di %7.2f r(mean)

	reg pen_soc $treatment, robust
	test ITT1=ITT2
	loc t1t2 = r(p)
	outreg2 using "Table2.tex", replace keep(ITT2)  addtext(Controls, No, Standard errors, Robust, Control mean, `c_mean') dec(3) label addnote("\begin{minipage}{\textwidth}\textit{Notes:} The table displays the estimate of OLS regression models when outcome Y of individual i is regressed on the treatment and a set of covariates. Each column in the table corresponds to a different specification. First column in each set has no controls. Second and third columns include the following controls: Sex, Ethnicity, Age, Education, Employment, Victimization, Perception of neighborhood insecurity, Left ideology, Crime, violence and security as the main social problem, A police officer asked for a bribe in the last 12 months, Individual watches news very frequently, and fixed effects at the level of sample stratification. Third columns show clustered standard errors at the level of stratification of the survey. Standard errors in parentheses. *** p<0.01, ** p<0.05, * p<0.1 \end{minipage}")

	reg pen_soc ITT1 ITT2 $vars_str, robust
	test ITT1=ITT2
	loc t1t2 = r(p)
	outreg2 using "Table2.tex", append keep(ITT2)  addtext(Controls, Yes, Standard errors, Robust, Control mean, `c_mean') dec(3) label

	reg pen_soc ITT1 ITT2 $vars_str, cl(cluster)
	test ITT1=ITT2
	loc t1t2 = r(p)
	outreg2 using "Table2.tex", append keep(ITT2)  addtext(Controls, Yes, Standard errors, Cluster, Control mean, `c_mean') dec(3) label

	foreach v in pen_det acceptmanodura{
		su `v' if treatment==0
		loc c_mean`v' : di %7.2f r(mean)
		
		reg `v' $treatment, robust
		test ITT1=ITT2
		loc t1t2 = r(p)
		
		outreg2 using "Table2.tex", append keep(ITT2)  addtext(Controls, No, Standard errors, Robust, Control mean, `c_mean`v'') dec(3) label
		
		reg `v' $treatment $vars_str, robust
		test ITT1=ITT2
		loc t1t2 = r(p)
		
		outreg2 using "Table2.tex", append keep(ITT2)  addtext(Controls, Yes, Standard errors, Robust, Control mean, `c_mean`v'') dec(3) label
		
		reg `v' $treatment $vars_str, cl(cluster)
		test ITT1=ITT2
		loc t1t2 = r(p)
		
		outreg2 using "Table2.tex", append keep(ITT2)  addtext(Controls, Yes, Standard errors, Cluster, Control mean, `c_mean`v'') dec(3) label
	}
		
	

** b. Figure 3 - Coins assigned to punitiveness and social policies among countries
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
if 1==0 {
	preserve
		use "$data\Coins_countries.dta", clear
	
		foreach v in punitivism diff_pun_soc{
			separate `v', by(country==1)
		}
		
		graph bar punitivism0 diff_pun_soc0 punitivism1 diff_pun_soc1 , over(country) bar(1, bfcolor(maroon%50) blcolor(maroon)) bar(2, bfcolor(navy%50) blcolor(navy)) bar(3, bfcolor(maroon) blcolor(maroon)) bar(4, bfcolor(navy) blcolor(navy))  blabel(bar) legend(order(3 "Coins assigned to punitiveness (control group)" 4 "Difference between punitiveness and social coins (control group)") r(2))
		graph export "Figure3.pdf", as(pdf) replace 
	restore 
}
	

** c. Figure 4 - Average Treatment Effect of Information 
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
	eststo pen_soc: 	reg pen_soc ITT1 ITT2 $vars_str, cl(cluster)
	eststo pen_det: 	reg pen_det ITT1 ITT2 $vars_str, cl(cluster)
	eststo mano_dura: 	reg acceptmanodura ITT1 ITT2 $vars_str, cl(cluster)

	coefplot (pen_soc, offset(0.15))(pen_det, offset(0))(mano_dura, offset(-0.15)), keep(ITT2) coeflabels(, notick labsize(medsmall) labcolor(black) labgap(1) ) drop(_cons) levels(99 95 90) ciopts(recast(rcap) lcolor(gray%20 black%40 black%100)) citop xline(0, lcolor(black) lwidth(thin) lpattern(dash)) xlabel(,labsize(small) angle(horizontal) format(%7.1f))  xtitle("Treatment Effect", size(small)) legend(order(9 "Accept Mano Dura" 5 "Punishment-Detection" 1 "Punishment-Social") r(1) size(vsmall)) ylabel(,labsize(small))
	graph export "Figure4.pdf", as(pdf) replace 
	graph close _all



*---------------------------------------*
* 3. APPENDIX RESULTS					*
*---------------------------------------*

** a. Table A1 - Impact of Information about Prisoner's Education on Policy Preferences (coin assignment - raw)
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
	su pen_coin if treatment==0
	loc c_mean : di %7.2f r(mean)

	reg pen_coin $treatment, robust
	test ITT1=ITT2
	loc t1t2 = r(p)
	outreg2 using "TableA1.tex", replace keep($treatment) addstat(T1=T2, `t1t2') addtext(Controls, No, Standard errors, Robust, Control mean, `c_mean') dec(3) label addnote("\begin{minipage}{\textwidth}\textit{Notes:} The table displays the estimate of OLS regression models when outcome Y of individual i is regressed on the treatment and a set of covariates. Each column in the table corresponds to a different specification. First column in each set has no controls. Second and third columns include the following controls: Sex, Ethnicity, Age, Education, Employment, Victimization, Perception of neighborhood insecurity, Left ideology, Crime, violence and security as the main social problem, A police officer asked for a bribe in the last 12 months, Individual watches news very frequently, and fixed effects at the level of sample stratification. Third columns show clustered standard errors at the level of stratification of the survey. Standard errors in parentheses. *** p<0.01, ** p<0.05, * p<0.1 \end{minipage}")

	reg pen_coin ITT1 ITT2 $vars_str, robust
	test ITT1=ITT2
	loc t1t2 = r(p)
	outreg2 using "TableA1.tex", append keep($treatment) addstat(T1=T2, `t1t2') addtext(Controls, Yes, Standard errors, Robust, Control mean, `c_mean') dec(3) label

	reg pen_coin ITT1 ITT2 $vars_str, cl(cluster)
	test ITT1=ITT2
	loc t1t2 = r(p)
	outreg2 using "TableA1.tex", append keep($treatment) addstat(T1=T2, `t1t2') addtext(Controls, Yes, Standard errors, Cluster, Control mean, `c_mean') dec(3) label

	foreach v in det_coin social_coin{
		su `v' if treatment==0
		loc c_mean`v' : di %7.2f r(mean)
		
		reg `v' $treatment, robust
		test ITT1=ITT2
		loc t1t2 = r(p)
		
		outreg2 using "TableA1.tex", append keep($treatment) addstat(T1=T2, `t1t2') addtext(Controls, No, Standard errors, Robust, Control mean, `c_mean`v'') dec(3) label
		
		reg `v' $treatment $vars_str, robust
		test ITT1=ITT2
		loc t1t2 = r(p)
		
		outreg2 using "TableA1.tex", append keep($treatment) addstat(T1=T2, `t1t2') addtext(Controls, Yes, Standard errors, Robust, Control mean, `c_mean`v'') dec(3) label
		

		reg `v' $treatment $vars_str, cl(cluster)
		test ITT1=ITT2
		loc t1t2 = r(p)
		
		outreg2 using "TableA1.tex", append keep($treatment) addstat(T1=T2, `t1t2') addtext(Controls, Yes, Standard errors, Cluster, Control mean, `c_mean`v'') dec(3) label
	}
		



** b. Table A2 - Table A2 - Robustness checks of the Impact of Information about Prisioner's Education on Policy Preferences (SURE, Shares, Ratios) 
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

cap texdoc close
	texdoc init TableA2, replace force
	tex \begin{table}[H]
	tex \centering
	tex \scriptsize		
	tex \caption{Impact of Information about Prisoner's Education on Policy Preferences - Robustness \label{tab:robustness}}
	tex \begin{tabular}{l*{8}{c}}			
	tex \hline \hline
	tex 					& \multicolumn{2}{c}{Seemly Unrelated Regression} & \multicolumn{3}{c}{Share of total coins assigned}	& \multicolumn{3}{c}{Ratios} \\
	tex \textbf{Variable}  	& Punishment & Social & Pun/Total & Det/Total & Soc/Total & Pun/Soc & Pun/Det & Det/Soc \\
	tex \cmidrule(lr){2-3} \cmidrule(lr){4-6} \cmidrule(lr){7-9}
	tex & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\
	tex \midrule
	
	glo l1 = ""
	glo l2 = ""
	glo l3 = ""
	glo l4 = ""
	glo l5 = ""
	glo l6 = ""
	
	
	sureg (sh_pen ITT1 ITT2 $vars_str)(sh_social ITT1 ITT2 $vars_str), isure 
		
	loc n0 = e(N)
	loc df0 = e(N)-e(rank)
		
	loc i=0
	foreach v in pen social{
		loc ++i 
		
		*loc i=2
		*loc v="pen"
			
		loc b`i' : di %7.3f [sh_`v']ITT2
		loc c`i' : di %7.3f [sh_`v']_cons
		
		if `i'==1{
			loc seb`i'	: di %7.3f sqrt(e(V)[2,2])
			loc sec`i'	: di %7.3f sqrt(e(V)[28,28])
		}
		
		if `i'==2{
			loc seb`i'	: di %7.3f sqrt(e(V)[30,30])
			loc sec`i'	: di %7.3f sqrt(e(V)[56,56])
		}

		
		
		foreach x in b c{
			loc t`x'`i' = ``x'`i''/`se`x'`i''
			loc p`x'`i' : di %7.3f 2*ttail(`df0',abs(`t`x'`i''))	
			loc star`x'`i' = ""
			if ((`p`x'`i'' < 0.1))  loc star`x'`i' = "*" 
			if ((`p`x'`i'' < 0.05)) loc star`x'`i' = "**" 
			if ((`p`x'`i'' < 0.01)) loc star`x'`i' = "***" 
		}
				
		test [sh_`v']ITT1=[sh_`v']ITT2
		loc wald`i': di %7.3f r(p)
		
		di ", `seb`i'' `tb`i'' `pb`i''  `wald`i''"
		
	glo l1 = "$l1 & `b`i'' `starb`i''"
	glo l2 = "$l2 & (`seb`i'')"
	glo l3 = "$l3 & `c`i'' `starc`i''"
	glo l4 = "$l4 & (`sec`i'')"
	glo l5 = "$l5 & `n0' "
	glo l6 = "$l6 & `wald`i''"
	
	}	
	
	loc i=0
	foreach v in sh_pen sh_det sh_social pensoc_ratio pendet_ratio detsoc_ratio{
		loc ++i
		
		reg `v' ITT1 ITT2 $vars_str, vce(robust) 
		loc n`i'=e(N)
		
		loc c`i'	: di %7.3f _b[_cons]
		loc sec`i'	: di %7.3f _se[_cons]
		loc b`i' 	: di %7.3f _b[ITT2]
		loc seb`i' 	: di %7.3f _se[ITT2]
		
		foreach x in b c{
			loc t`x'`i' = ``x'`i''/`se`x'`i''
			loc p`x'`i' : di %7.3f 2*ttail(e(df_r),abs(`t`x'`i''))	
			loc star`x'`i' = ""
			if ((`p`x'`i'' < 0.1))  loc star`x'`i' = "*" 
			if ((`p`x'`i'' < 0.05)) loc star`x'`i' = "**" 
			if ((`p`x'`i'' < 0.01)) loc star`x'`i' = "***" 
		}
		
		test ITT1=ITT2
		loc wald`i': di %7.3f r(p)
		
		glo l1 = "$l1 & `b`i'' `starb`i''"
		glo l2 = "$l2 & (`seb`i'')"
		glo l3 = "$l3 & `c`i'' `starc`i''"
		glo l4 = "$l4 & (`sec`i'')"
		glo l5 = "$l5 & `n`i'' "
		glo l6 = "$l6 & `wald`i''"
		
	
	}
	
	
	tex Treatment			$l1 \\
	tex 					$l2 \\
	tex \addlinespace[1.5pt] 
	tex Constant			$l3 \\
	tex  					$l4 \\
	tex \addlinespace[3pt] 
	tex Observations 		$l5 \\
	tex \addlinespace[1.5pt] 
	tex Wald test	 		$l6 \\
	tex \hline \hline
	tex \addlinespace[2pt]
	tex \multicolumn{9}{l}{\footnotesize{\begin{minipage}{\textwidth}\textit{Notes:} This table presents alternative definitions of the dependent variable and specifications of the model. The first five columns estimate the effect of the treatment on shares over the total number of coins an individual assigned. The first two columns use a Seemly Unrelated Regression Method to assess the effect of the treatment considering that the decision of coin allocation is simultaneous and limited, i.e, if an individual decides to allocate x number of  coins in punitive policies, she knows that she can only assign 10-x to the other alternatives, so the decision is simultaneous and with limited resources. Columns (6) to (8) estimate the effect on ratios. It states how many coins are assigned to \textit{Punitive} measures compared to \textit{social} policies when people receive the informational treatment -column 6. As we control for having received the placebo informational vignette, row \textit{Wald test} displays the test of equality of coefficients (\$\beta_{Placebo}\$=\$\beta_{Treatment}\$). \end{minipage}}}
	tex \end{tabular}
	tex \end{table}	
	texdoc close	



** c. Figure A1 - Distribution of coins - control group
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

graph box pen_coin det_coin soc1_coin soc2_coin acceptmanodura if treatment==0 
graph export "FigureA1.pdf", replace as(pdf)



** d. Figure A2 - Distribution of coins - treatment vs. control
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

	foreach v in pen social{
		tw	(hist `v'_coin if treatment==0, discrete percent lcolor(gs12) fcolor(gs12)) ///
		(hist `v'_coin if treatment==2, discrete percent fcolor(none) lcolor(red)), ///
		title("Coins assigned to `:variable label `v'_coin'", size(small)) ///
		ytitle(, size(small)) ylabel(, labsize(vsmall) angle(horizontal) format(%7.0f)) ///
		legend(order(1 "Control" 2 "Treatment") size(vsmall)) xlabel(,labsize(vsmall)) ///
		xtitle("", size(small)) ///
		name(`v'_coin, replace)
	}

	grc1leg pen_coin social_coin, legendfrom(pen_coin) ycom c(1) title("", size(small)) name(distribution, replace)
	graph di distribution, xsize(16) ysize(20)

	graph export "FigureA2.pdf", replace as(pdf)



** e. Figure A4 - Average Treatment Effect of Information and Placebo
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

	eststo pen_soc: 	reg pen_soc ITT1 ITT2 $vars_str, cl(cluster)
	eststo pen_det: 	reg pen_det ITT1 ITT2 $vars_str, cl(cluster)
	eststo mano_dura: 	reg acceptmanodura ITT1 ITT2 $vars_str, cl(cluster)
	
	coefplot pen_soc, drop(_cons) keep(ITT1 ITT2) subtitle(Punishment - Social, box bexpand lstyle(none) size(small)) name(pen_soc, replace) mlcolor(orange_red) mfcolor(orange_red) xline(0, lpattern(dash) lcolor(black)) levels(99 95 90) ciopts(recast(rcap) lcolor(midblue%20 blue%40 blue%100)) ylabel(, labsize(small))

	coefplot pen_det, drop(_cons) keep(ITT1 ITT2) subtitle(Punishment - Detection, box bexpand lstyle(none) size(small)) name(pen_det, replace) nodraw mlcolor(orange_red) mfcolor(orange_red) xline(0, lpattern(dash) lcolor(black)) levels(99 95 90) ciopts(recast(rcap) lcolor(midblue%20 blue%40 blue%100)) ylabel(, labsize(small))

	coefplot mano_dura, drop(_cons) keep(ITT1 ITT2) subtitle(Accept Mano Dura, box bexpand lstyle(none) size(small)) name(mano, replace) nodraw mlcolor(orange_red) mfcolor(orange_red) xline(0, lpattern(dash) lcolor(black)) levels(99 95 90) ciopts(recast(rcap) lcolor(midblue%20 blue%40 blue%100)) ylabel(, labsize(small))

	graph combine pen_soc pen_det mano, imargin(small) c(1) name(combined, replace) xcom
	graph di combined, xsize(16) ysize(20)
	graph export "FigureA4.pdf", as(pdf) replace 



** f. Figure A5 - Heterogeneous effects: Main problem crime and violence
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

	foreach v in pen_soc pen_det acceptmanodura{
		reg `v' ITT1##c.d_prob_crimebroad ITT2##c.d_prob_crimebroad $vars_str, cl(cluster)
		margins, dydx(ITT2) at(d_prob_crimebroad =(0(1)1))
		marginsplot, recast(scatter) yline(0) ylabel(,labsize(small) angle(0) format(%5.1f)) ytitle("d(`:variable label `v'')/d(T)", size(small)) recastci(rcap) level(90) addplot(hist d_prob_crimebroad, percent yaxis(2) yscale(alt) lcolor(gs12%30) fcolor(gs12%30) ylabel(, labsize(small) angle (0) axis(2)) xlabel(, labsize(small)) xscale(range(-0.1 1.1)) xtitle(, size(small)) ytitle("% Observations", size(small) axis(2)) legend(order(2 "Estimate" 3 "% of people") size(vsmall))) title("`:variable label `v''", size(small)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) name(`v', replace) xlabel(0 "No" 0.2 " " 0.4 " " 0.6 " " 0.8 " " 1 "Yes")	
	}

	grc1leg pen_soc pen_det acceptmanodura, c(1) name(het_d_prob_crimebroad, replace)
	graph di het_d_prob_crimebroad, xsize(12) ysize(20)
	graph export "FigureA5.pdf", as(pdf) replace 



** Figure A6 - Heterogeneous effects: perception of neighborhood insecurity
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

	foreach v in pen_soc pen_det acceptmanodura{
		reg `v' ITT1##c.neigh_insec ITT2##c.neigh_insec $vars_str, cl(cluster)
		margins, dydx(ITT2) at(neigh_insec =(1(1)4))
		marginsplot, recast(scatter) yline(0) ylabel(,labsize(small) angle(0) format(%5.1f)) ytitle("d(`:variable label `v'')/d(T)", size(small)) recastci(rcap) level(90) addplot(hist neigh_insec, percent yaxis(2) yscale(alt) lcolor(gs12%30) fcolor(gs12%30) ylabel(, labsize(small) angle (0) axis(2)) xlabel(, labsize(small)) xscale(range(1 4)) xtitle(, size(small)) ytitle("% Observations", size(small) axis(2)) legend(order(2 "Estimate" 3 "% of people") size(vsmall))) title("`:variable label `v''", size(small)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) name(`v', replace)	
	}

	grc1leg pen_soc pen_det acceptmanodura, c(1) name(het_neigh_insec_con, replace)
	graph di het_neigh_insec_con, xsize(12) ysize(20)
	graph export "FigureA6.pdf", as(pdf) replace 



** Figure A7 - Heterogeneous effects: Education level 
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*

	foreach v in pen_soc pen_det acceptmanodura{
		reg `v' ITT1##c.educa ITT2##c.educa $vars_str, cl(cluster)
		margins, dydx(ITT2) at(educa =(0(1)3))
		marginsplot, recast(scatter) yline(0) ylabel(,labsize(small) angle(0) format(%5.1f)) ytitle("d(`:variable label `v'')/d(T)", size(small)) recastci(rcap) level(90) addplot(hist educa, percent yaxis(2) yscale(alt) lcolor(gs12%30) fcolor(gs12%30) ylabel(, labsize(small) angle (0) axis(2)) xlabel(, labsize(small)) xscale(range(0 3)) xtitle(, size(small)) ytitle("% Observations", size(small) axis(2)) legend(order(2 "Estimate" 3 "% of people") size(vsmall))) title("`:variable label `v''", size(small)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) name(`v', replace)	
	}

	grc1leg pen_soc pen_det acceptmanodura, c(1) name(het_education_lev, replace)
	graph di het_education_lev, xsize(12) ysize(20)
	graph export "FigureA7.pdf", as(pdf) replace 



** Figure A8 - Heterogeneous effects: government involvement in income inequality alleviation policies
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
	
	foreach v in pen_soc pen_det acceptmanodura{
		reg `v' ITT1##c.reduce_ineq ITT2##c.reduce_ineq $vars_str, robust
		margins, dydx(ITT2) at(reduce_ineq=(1(1)7))
		marginsplot, recast(scatter) yline(0) ylabel(,labsize(small) angle(0) format(%5.1f)) ytitle("d(`:variable label `v'')/d(T)", size(small)) recastci(rcap) level(90) addplot(hist reduce_ineq, percent yaxis(2) yscale(alt) lcolor(gs12%30) fcolor(gs12%30) ylabel(, labsize(small) angle (0) axis(2)) xlabel(, labsize(small)) xscale(range(0 8)) xtitle(, size(small)) ytitle("% Observations", size(small) axis(2)) legend(order(2 "Estimate" 3 "% of people") size(vsmall))) title("`:variable label `v''", size(small)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) xlabel(0 " " 1 "Strongly disagree" 7 "Strongly agree" 8 " ")  name(`v', replace)
	}
	grc1leg pen_soc pen_det acceptmanodura, c(1) name(het_reduc_ineq, replace)
	graph di het_reduc_ineq, xsize(12) ysize(20)
	graph export "FigureA8.pdf", as(pdf) replace 	
	
graph close _all




